package org.jz.gae.redbook.spb.client.slate.family;

import org.jz.gae.redbook.spb.shared.FamilyEntityView;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;

public class FamilyPropertiesPanel extends Composite 
{
	  private final TextBox familyAlias = new TextBox();
	  private final TextBox familyEnglerCode = new TextBox();
	  private final TextBox familyLatName = new TextBox();
	  private final TextBox familyLatNameAuthor = new TextBox();
	  private final TextBox familySynName = new TextBox();
	  private final TextBox familySynNameAuthor = new TextBox();
	  private final TextBox familyRusName = new TextBox();
	  private final TextArea familyNote = new TextArea();
	  private final FlexTable detailsTable;
	  
	  public FamilyPropertiesPanel()
	  {
		  SimplePanel contentDetailsDecorator = new SimplePanel();
	    contentDetailsDecorator.setWidth("18em");
	    initWidget(contentDetailsDecorator);

	    VerticalPanel contentDetailsPanel = new VerticalPanel();
	    contentDetailsPanel.setWidth("100%");

	    // Create the contacts list
	    //
	    detailsTable = new FlexTable();
	    detailsTable.setCellSpacing(0);
	    detailsTable.setWidth("100%");
	    detailsTable.addStyleName("contacts-ListContainer");
	    detailsTable.getColumnFormatter().addStyleName(1, "add-contact-input");
	    initDetailsTable();
	    contentDetailsPanel.add(detailsTable);
	    
	    contentDetailsDecorator.add(contentDetailsPanel);
	  }
	  
	  private void initDetailsTable() {
	    detailsTable.setWidget(0, 0, new Label("Сокращение:"));
	    detailsTable.setWidget(0, 1, familyAlias);
	    detailsTable.setWidget(0, 2, new Label("DT код:"));
	    detailsTable.setWidget(0, 3, familyEnglerCode);
	    detailsTable.setWidget(1, 0, new Label("Принятое наименование:"));
	    detailsTable.setWidget(1, 1, familyLatName);
	    detailsTable.setWidget(1, 2, new Label("Авторство:"));
	    detailsTable.setWidget(1, 3, familyLatNameAuthor);
	    detailsTable.setWidget(2, 0, new Label("Синоним:"));
	    detailsTable.setWidget(2, 1, familySynName);
	    detailsTable.setWidget(2, 2, new Label("Авторство:"));
	    detailsTable.setWidget(2, 3, familySynNameAuthor);
	    detailsTable.setWidget(3, 0, new Label("Русское наименование:"));
	    detailsTable.setWidget(3, 1, familyRusName);
	    detailsTable.setWidget(4, 0, new Label("Примечание:"));
	    detailsTable.setWidget(4, 1, familyNote);
	    familyLatName.setFocus(true);
	  }

	public FamilyEntityView pickUpInformation()
	{
		FamilyEntityView family = new FamilyEntityView();
		/**/
	    family.setFamilyAlias(familyAlias.getValue());
	    family.setFamilyEnglerCode(Integer.parseInt(familyEnglerCode.getValue()));
	    family.setFamilyLatName(familyLatName.getValue());
	    family.setFamilyLatNameAuthor(familyLatNameAuthor.getValue());
	    family.setFamilySynName(familySynName.getValue());
	    family.setFamilySynNameAuthor(familySynNameAuthor.getValue());
	    family.setFamilyRusName(familyRusName.getValue());
	    family.setFamilyNote(familyNote.getValue());
		return family;
	}
	
	public void displayInformation(
			FamilyEntityView _Family)
	{
	    familyAlias.setValue(_Family.getFamilyAlias());
	    familyEnglerCode.setValue(_Family.getFamilyEnglerCode() + "");
	    familyLatName.setValue(_Family.getFamilyLatName());
	    familyLatNameAuthor.setValue(_Family.getFamilyLatNameAuthor());
	    familySynName.setValue(_Family.getFamilySynName());
	    familySynNameAuthor.setValue(_Family.getFamilySynNameAuthor());
	    familyRusName.setValue(_Family.getFamilyRusName());
	    familyNote.setValue(_Family.getFamilyNote());
	}
	
	public void lockInterface()
	{
	    familyAlias.setEnabled(false);
	    familyEnglerCode.setEnabled(false);
	    familyLatName.setEnabled(false);
	    familyLatNameAuthor.setEnabled(false);
	    familySynName.setEnabled(false);
	    familySynNameAuthor.setEnabled(false);
	    familyRusName.setEnabled(false);
	    familyNote.setEnabled(false);
	}
}
